<?php

use App\Models\Comment;
use App\Models\Post;
use Illuminate\Database\Seeder;

class CommentSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $users = Post::query()->pluck('user_id')->toArray();
        $post_ids = Post::query()->pluck('id')->toArray();
        $faker = app(Faker\Generator::class);
        $comments =  factory(Comment::class)->times(100)->make()->each(function ($comment,$index) use($users,$post_ids,$faker){
            $comment->user_id = $faker->randomElement($users);
            $comment->post_id = $faker->randomElement($post_ids);
        });
        Comment::query()->insert($comments->toArray());
    }
}
